<template>
  <el-dialog title="启用/禁用" v-model="visible" :width="600" destroy-on-close @closed="$emit('closed')">
    <el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="120px">
		
      <el-form-item label="账号" prop="username">
        <el-input v-model="form.username" placeholder="请输入账号" clearable disabled></el-input>
      </el-form-item>
	  
      <el-form-item label="启用状态" prop="isDisabled">
		<el-switch v-model="form.isDisabled" :active-value="0" :inactive-value="1"></el-switch>
      </el-form-item>	  
	
      <el-form-item label="操作原因" prop="cause">
        <el-input v-model="form.cause" placeholder="请输入备注" clearable></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible=false" >取 消</el-button>
      <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
	import setting from './setting'
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					id: null,
					username: '',
					isDisabled: 0,
					cause: '',
					_: ""
				}
			}
		},
		mounted() {
		},
		methods: {
			open(){
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var d = {
							id : this.form.id,
							value: this.form.isDisabled,
							cause: this.form.cause
						}
						var res = await setting.api.disable.post(d)
						this.isSaveing = false;
						if(res.code == setting.successCode){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				})
			},
			//表单注入数据
			setData(data){
				this.form.id = data.id
				this.form.username = data.username
				this.form.isDisabled = data.isDisabled
			}
		}
	}
</script>

<style>
</style>
